package com.ruoyi.web.controller.system;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.CmsArticle;
import com.ruoyi.system.service.ICmsArticleService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/cms/article")
public class CmsArticleController extends BaseController {

    @Resource
    private ICmsArticleService cmsArticleService;

    @GetMapping("/list")
    public TableDataInfo list(CmsArticle article) {
        startPage();
        List<CmsArticle> list = cmsArticleService.selectCmsArticleList(article);
        return getDataTable(list);
    }

    @GetMapping(value = "/{articleId}")
    public AjaxResult getInfo(@PathVariable Long articleId) {
        return AjaxResult.success(cmsArticleService.selectCmsArticleById(articleId));
    }

    @Log(title = "资讯文章", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CmsArticle article) {
        return toAjax(cmsArticleService.insertCmsArticle(article));
    }

    @Log(title = "资讯文章", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CmsArticle article) {
        return toAjax(cmsArticleService.updateCmsArticle(article));
    }

    @Log(title = "资讯文章", businessType = BusinessType.DELETE)
    @DeleteMapping("/{articleIds}")
    public AjaxResult remove(@PathVariable Long[] articleIds) {
        return toAjax(cmsArticleService.deleteCmsArticleByIds(articleIds));
    }
}


